package leetcode.d1;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: hang an
 * @Date: 2025/5/4
 * @Description:
 */
public class R1128 {
    public int numEquivDominoPairs(int[][] dominoes) {
        Map<String,  Integer> cnt = new HashMap<>();
        for (int[] dominoe : dominoes) {
            int l = dominoe[0];
            int r = dominoe[1];
            String key = l < r ? l + " " + r : r + " " + l;
            cnt.merge(key, 1, Integer::sum);
        }
        int res = 0;
        for (Integer value : cnt.values()) {
            res += value * (value - 1) / 2;
        }
        return res;
    }
}
